package cn.wolfcode.util;

import cn.wolfcode.domain.Employee;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.Servlet;
import javax.servlet.http.HttpSession;
import java.util.List;

public class UserContext {


    public static Employee getCurrentUser(){

        return (Employee) SecurityUtils.getSubject().getPrincipal();
    }

 /*   public static final String USER_IN_SESSION = "USER_IN_SESSION";


    public static final String EXPRESSION_IN_SESSION = "EXPRESSION_IN_SESSION";


    *//**
     *
     * 获取Session对象
     * @return
     *//*

    public static HttpSession getSession(){

        //Springmvc提供的工具,可以在任意地方获取到request对象,response对象,session对象
        ServletRequestAttributes attrs = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        return attrs.getRequest().getSession();
    }

    *//**
     *
     * 从session获取当前登录对象
     * @return
     *//*
    public static Employee getCurrentUser(){

        return (Employee)getSession().getAttribute(USER_IN_SESSION);
    }

    *//**
     *
     * 设置当前登录用户session中
     * @param employee
     *//*

    public static void setCurrentUser(Employee employee){

        getSession().setAttribute(USER_IN_SESSION, employee);
    }


    *//**
     *
     * 从session获取权限对象
     * @return
     *//*
    public static List<String> getExpression(){

        return (List<String>)getSession().getAttribute(EXPRESSION_IN_SESSION);
    }

    *//**
     *
     * 设置当前权限到session中
     * @param list
     *//*

    public static void setExpression(List<String> list){

        getSession().setAttribute(EXPRESSION_IN_SESSION, list);
    }*/
}
